/**
 * 匠言知识付费v2.0.0
 * Author: 山西匠言网络科技有限公司
 * 这不是一个免费软件，它受限于许可条款，你可以访问https://www.zsfzxkc.cn/获取更多详细信息。
 * This is not a free software, it under the license terms, you can visit https://www.zsffzxkc.cn/ get more details.
 */
<template>
	<view class="container">
		<jy-quick-btns></jy-quick-btns>
		<view class="beijing">
			<image src="../static/jigoulogin.jpg" mode="aspectFill"></image>
		</view>
		<form @submit="submit" :model="applyForm">
			<input class="phone" v-model="applyForm.phone" type="number" placeholder="*请输入负责人手机号" />
			<input class="phone" type="password" v-model="applyForm.password" placeholder="*请输入密码" />
			<view style="padding: 30upx;font-size: 28upx;">
				<view style="padding: 15upx;color: orangered;font-weight: 700;">温馨提示</view>
				<view style="padding: 15upx;color: orangered;">1.演示账号17636002018 密码123456</view>
				<view style="padding: 15upx;color: orangered;">2.如未注册请点击机构注册进行入驻申请</view>
			</view>
			<view class="submit">
				<button form-type="submit" type="primary">立即登录</button>
				<button @click="reg" type="warn">机构注册</button>
			</view>
		</form>
	</view>
</template>

<script>
	import {checkUserinfo} from '@/request/checkUserinfo'
	export default {
		data() {
			return {
				userinfo: {},
				pxbinfo:{},
				flag:false,
				applyForm: {
					phone: '',
					password: '',
				}
			};
		},
		
		onShow() {
			checkUserinfo()
			let userinfo=uni.getStorageSync('userinfo')
			this.userinfo = userinfo.userdata
			this.pxbinfo=uni.getStorageSync('pxbinfo')
			if(this.pxbinfo){
				this.checkpxbinfo(this.pxbinfo.id)
			}
		},
		onShareAppMessage(res) {
			let path = getCurrentPages()
			let path_share = path[0].$page.fullPath
			let path_title = path[0].data.title
			let userinfo = uni.getStorageSync('userinfo')
			let base_set = uni.getStorageSync('base_set')
			if(userinfo.uid=='' || !userinfo.uid){
				uni.navigateTo({
					url:'../login/login'
				})
				return {
					title: '请先登录后再分享给好友',
					path: ''
				}
			}else{
				if (res.from === 'button') {
					
				}
				return {
					title: base_set.title,
					path: `${path_share}?pid=${userinfo.uid}`
				}
			}
		},
		methods: {
			checkpxbinfo(id){
				const BASE_URL = uni.BASE_URL
				uni.request({
					url: BASE_URL+'index/pxb/jigouinfo',
					method:'POST',
					data:{
						id:id,
					},
					success:(res) =>{
						console.log(res.data);
						if(res.data.code==0){
							this.pxbinfo=res.data.data
							uni.navigateTo({
								url:'../jigou-center/jigou-center'
							})
						}else{
							setTimeout(()=>{
								uni.navigateTo({
									url:'../jigou-reg/jigou-reg'
								})
							},1500)
						}
					},
					fail:(res)=> {
						console.log(res.data);
					}
				});
			},
			reg(){
				uni.navigateTo({
					url:'../jigou-reg/jigou-reg'
				})
			},
			submit () {
				if(this.applyForm.password == '' || this.applyForm.phone == '') {
					uni.showToast({
						title: '手机号、密码不能为空',
						duration: 2000,
						icon:'none'
					});
					return false;
				}
				if(!/^1[3-9]\d{9}$/.test(this.applyForm.phone)) {
					uni.showToast({
						title: '手机号码格式不正确,请重试',
						duration: 2000,
						icon:'none'
					});
					return false;
				}
				const BASE_URL=uni.BASE_URL
				uni.request({
					url: BASE_URL+'index/pxb/login',
					data: this.applyForm,
					method:'POST',
					success:(res) =>{
						console.log(res.data);
						if(res.data.code=="0"){
							uni.showToast({
								title: res.data.msg,
								duration: 1500
							});
							uni.setStorageSync('pxbinfo',res.data.data);
							uni.navigateTo({
								url:'/pages/sub/jigou-center/jigou-center'
							})
						}else{
							uni.showModal({
								title: '提示',
								content: res.data.msg,
								showCancel:false,
								success: function (res) {
									if (res.confirm) {
										console.log('用户点击确定');
									}
								}
							});
						}
					},
					fail:(res)=> {
						console.log(res.data);
					}
				});
			},
		}
	}
</script>

<style lang="less" scoped>

.beijing {
	image {
		width: 750upx;
		height: 350upx;
	}
	.info {
		display: flex;
		flex-direction: column;
		align-items: center;
		position: absolute;
		top: 55upx;
		left: 300upx;
		image {
			width: 150upx;
			height: 150upx;
			border-radius: 50%;
		}
		text {
			font-size: 34upx;
			color: #fff;
			margin-top: 20upx;
		}
	}
}

form {
	.name, .phone {
		width: 690upx;
		height: 80upx;
		border: 2upx solid #333;
		border-radius: 10upx;
		margin: 20upx 30upx 0;
		padding-left: 20upx;
		box-sizing: border-box;
	}
	.file {
		image {
			width: 150upx;
			height: 150upx;
			margin: 30upx 0 0 30upx;
			border: 2upx dotted #eee;
			border-radius: 10upx;
			box-shadow: 5upx 5upx 5upx 5upx #ddd;
		}
		text {
			font-size: 30upx;
			color: #333;
			margin-left: 20upx;
		}
	}
	.code {
		width: 690upx;
		height: 80upx;
		// background-color: orange;
		margin: 20upx 30upx 0;
		box-sizing: border-box;
		display: flex;
		position: relative;
		.shuxian {
			position: absolute;
			top: 16upx;
			right: 200upx;
			color: #ddd;
		}
		input {
			width: 490upx;
			height: 80upx;
			border: 2upx solid #333;
			border-right: 0;
			border-radius: 10upx 0 0 10upx;
			padding-left: 20upx;
			box-sizing: border-box;
		}
		.sendcode {
			width: 200upx;
			height: 80upx;
			text-align: center;
			line-height: 76upx;
			border: 2upx solid #333;
			border-left: 0;
			border-radius: 0 10upx 10upx 0;
			font-size: 30upx;
			color: #333;
			// padding: 0;
			box-sizing: border-box;
			background-color: #f5f5f5;
		}
	}
	.submit {
		width: 100%;
		height: 120upx;
		background-color: #fff;
		display: flex;
		justify-content: center;
		align-items: center;
		position: fixed;
		left: 0;
		bottom: 0;
		button {
			padding: 0 50rpx;
			height: 80upx;
			background-color: #4b89ff;
			border-radius: 80upx;
			color: #fff;
			line-height: 80upx;
		}
	}
}



</style>
